package routes

import (
	v1 "app/api/v1"
	"app/internal/app/middleware"
	"app/internal/pkg/config"

	"github.com/gin-contrib/gzip"
	"github.com/gin-gonic/gin"
)

func InitRouter() *gin.Engine {
	if config.Debug {
		gin.SetMode(gin.DebugMode)
	} else {
		gin.SetMode(gin.ReleaseMode)
	}

	router := gin.New()
	router.Use(gin.Logger())
	router.Use(gin.Recovery())
	router.SetTrustedProxies(nil)

	router_web := router.Group("/").Use(gzip.Gzip(gzip.DefaultCompression))
	{
		router_web.StaticFile("/", "./web/index.html")
		router_web.Static("/web", "./web")
	}

	router_v1 := router.Group("/api/v1")
	{
		router_v1.POST("/login", v1.Login)
		router_v1.POST("/register", v1.Register)

		// 登录后才能访问
		router_auth := router_v1.Group("/user").Use(middleware.JwtAuth())
		{
			router_auth.GET("", v1.GetUser)
		}
	}

	return router
}
